package com.patterns.prototype;
/**
 * 深复制
 * 原型模式复制羊 对象
 * 复制对象所有属性
 * @author huangke
 *
 */
public class DeepSheep implements Cloneable{
	private String name;
	private String type;
	private DeepColor color;
	@Override
	protected Object clone() throws CloneNotSupportedException {
		DeepSheep sheep = (DeepSheep) super.clone();
		// 深复制，对象类型属性复制
		sheep.color = (DeepColor) sheep.color.clone();
		return sheep;
	}
	public DeepSheep(String name, String type, DeepColor color) {
		this.name = name;
		this.type = type;
		this.color = color;
	}
	public DeepColor getColor() {
		return color;
	}
	public void setColor(DeepColor color) {
		this.color = color;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	@Override
	public String toString() {
		return "Sheep [name=" + name + ", type=" + type + ", color=" + color + "]";
	}
}

class DeepColor implements Cloneable{
	private String color;
	@Override
	protected Object clone() throws CloneNotSupportedException {
		return super.clone();
	}

	public DeepColor(String color) {
		super();
		this.color = color;
	}

	public String getColor() {
		return color;
	}

	public void setColor(String color) {
		this.color = color;
	}

	@Override
	public String toString() {
		return "Color [color=" + color + "]";
	}
}


